//
//  STMSetNewPwdViewController.m
//  StoreManagement
//
//  Created by centling on 16/6/2.
//  Copyright © 2016年 alfred. All rights reserved.
//

#import "STMSetNewPwdViewController.h"

@interface STMSetNewPwdViewController ()
@property (weak, nonatomic) IBOutlet UIButton *backButton;
@property (weak, nonatomic) IBOutlet UITextField *changePwdTextField;
@property (weak, nonatomic) IBOutlet UITextField *confirmPwdTextField;
@property (weak, nonatomic) IBOutlet UIButton *doneButton;

@end

@implementation STMSetNewPwdViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = MAINGRAYCOLOR;
    [self.backButton addTarget:self action:@selector(backButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [self.doneButton addTarget:self action:@selector(doneButtonClick) forControlEvents:UIControlEventTouchUpInside];
}

- (void)backButtonClick {
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)doneButtonClick {
    if ([self.changePwdTextField.text isEqualToString:@""]) {
        [GlobalUtil HUDShowMessage:@"请输入新密码" addedToView:self.view];
        return;
    }
    if ([self.confirmPwdTextField.text isEqualToString:@""]) {
        [GlobalUtil HUDShowMessage:@"请输入确认密码" addedToView:self.view];
        return;
    }
    if (![self.changePwdTextField.text isEqualToString:self.confirmPwdTextField.text]) {
        [GlobalUtil HUDShowMessage:@"两次密码输入不一致" addedToView:self.view];
        return;
    }
    [STMNetworkAPI modifyPwdWithSellerName:[UserDefaultHandler getUserDetaultString:kSellerName]
                                    newPwd:self.confirmPwdTextField.text
                                   success:^(STMLoginModel *result) {
                                       if ([result.code isEqualToString:@"200"]) {
                                           [UserDefaultHandler saveUserDetault:self.confirmPwdTextField.text key:kUserPwd];
                                           [self.presentingViewController.presentingViewController.presentingViewController dismissViewControllerAnimated:NO completion:nil];
                                       } else {
                                           [GlobalUtil HUDShowMessage:result.message addedToView:self.view];
                                       }
                                   }
                                   failure:^(NSError *err) {
                                       [GlobalUtil HUDShowMessage:@"请检查网络连接" addedToView:self.view];
                                   }];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
